package com.giaothong.http;

import org.json.JSONObject;

import android.content.Context;

import com.giaothong.config.Define;
import com.giaothong.config.ServerUrl;
import com.giaothong.http.core.HttpAsyncCallback;
import com.giaothong.http.core.HttpConnectionId;
import com.giaothong.http.core.NewHttpConnectionAsync;
import com.giaothong.utils.ALog;
import com.google.android.maps.GeoPoint;

public class HttpGetLocationInfoGoogleAPIRequest extends NewHttpConnectionAsync {

	public HttpGetLocationInfoGoogleAPIRequest(Context context, HttpAsyncCallback<JSONObject> callback) {
		super(context, HttpConnectionId.GET_LOCATION_INFO_REQUEST, callback);
	}

	/**
	 * Call this func to request to server
	 * 
	 * @param pram1
	 * @param param2
	 */
	public void request(GeoPoint location, String radius, String type) {
		// Create json object with data
		rootObj = new JSONObject();

		addParam("location", (double) (location.getLatitudeE6()) / 1000000 + "," + (double) location.getLongitudeE6() / 1000000);
		addParam("radius", "" + radius);
		addParam("sensor", "false");
		addParam("language", Define.LANGUAGE);
		addParam("key", ServerUrl.KEY_API_SEARCH_LOCATION);
		if (!type.equals(""))
		addParam("types ", type);

		// executable request
		ALog.i("Requests", ServerUrl.GET_LOCATION_INFO_URL + "___" + rootObj.toString());
		this.execute(ServerUrl.GET_LOCATION_INFO_URL);
	}

}